package com.timeshare.controller;

import com.timeshare.common.Result;
import com.timeshare.dto.SkillVO;
import com.timeshare.service.RecommendService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 推荐控制器
 */
@Tag(name = "推荐管理")
@RestController
@RequestMapping("/recommend")
public class RecommendController {
    
    private final RecommendService recommendService;
    
    public RecommendController(RecommendService recommendService) {
        this.recommendService = recommendService;
    }
    
    @Operation(summary = "获取个性化推荐")
    @GetMapping("/personalized")
    public Result<List<SkillVO>> getRecommendedSkills(
            Authentication authentication,
            @RequestParam(defaultValue = "10") Integer limit) {
        try {
            Long userId = (Long) authentication.getPrincipal();
            List<SkillVO> skills = recommendService.getRecommendedSkills(userId, limit);
            return Result.success(skills);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
    
    @Operation(summary = "获取热门技能")
    @GetMapping("/hot")
    public Result<List<SkillVO>> getHotSkills(@RequestParam(defaultValue = "10") Integer limit) {
        try {
            List<SkillVO> skills = recommendService.getHotSkills(limit);
            return Result.success(skills);
        } catch (Exception e) {
            return Result.error(e.getMessage());
        }
    }
}
